<?php

namespace Xin\LaravelFortify\Support;

use Illuminate\Support\Facades\DB;
use PDOException;

class DbUtil
{

	/**
	 * @param callable $callback
	 * @return void
	 * @throws PDOException
	 */
	public static function call(callable $callback)
	{
		try {
			return $callback();
		} catch (PDOException $e) {
			$data = $e->errorInfo;
			if (isset($data['PDO Error Info']) && $pdoErrorInfo = $data['PDO Error Info']) {
				// Numeric value out of range: 0 Out of range value for col
				if ($pdoErrorInfo['SQLSTATE'] == 22003) {
					return;
				}
			}

			throw $e;
		}
	}
}
